#!/usr/bin/env python
#
#       Interface2.py
#
#       Copyright 2008 karthikeyan S.<kaarthikeyapreyan@gmail.com>
#
#       This program is free software; you can redistribute it and/or modify
#       it under the terms of the GNU General Public License as published by
#       the Free Software Foundation; either version 2 of the License, or
#       (at your option) any later version.
#
#       This program is distributed in the hope that it will be useful,
#       but WITHOUT ANY WARRANTY; without even the implied warranty of
#       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#       GNU General Public License for more details.
#
#       You should have received a copy of the GNU General Public License
#       along with this program; if not, write to the Free Software
#       Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
#       MA 02110-1301, USA.

import wx

import help
import customize
import viewdefinitions
import moduledefinitions
import displaydefinitions
import listingdefinitions
import genericdefinitions
import activitydefinitions
import generatedefinitions
import transferdefinitions

class BaseFrame(wx.Frame):

    def __init__(self):

        wx.Frame.__init__(self, None, -1, "PyTestsGenerator",size=(900,700))

        ### Settings for File Menu
        self.file = wx.Menu()

        self.view=wx.Menu()

        self.gencase=wx.MenuItem(self.view,501,"Unittest Case",\
            "Recent Test Case generated")
        self.gencase.SetBitmap(wx.Bitmap\
            ('/usr/share/icons/pytestsgenerator/menu/genc.png'))
        self.view.AppendItem(self.gencase)

        self.rlog=wx.MenuItem(self.view,502,"Test Results",\
            "The Results of the TestCases Generated after Dry Run")
        self.rlog.SetBitmap(wx.Bitmap\
            ('/usr/share/icons/pytestsgenerator/menu/results.png'))
        self.view.AppendItem(self.rlog)

        self.tbar=wx.MenuItem(self.view,504,"ToolBar",\
            "Check to enable Toolbar",kind=wx.ITEM_CHECK)
        self.sbar=wx.MenuItem(self.view,505,"StatusBar",\
            "Check to enable Statusbar",kind=wx.ITEM_CHECK)

        self.view.AppendItem(self.tbar)
        self.view.AppendItem(self.sbar)

        self.view.Check(504, True)
        self.view.Check(505, True)

        self.settings=wx.Menu()

        self.file.AppendMenu(50,"&View",self.view,"View Activity Files")

        self.quit = wx.MenuItem(self.file, 52, '&Quit\tCtrl+Q',\
            "Exit the application")
        self.quit.SetBitmap(wx.Bitmap\
            ('/usr/share/icons/pytestsgenerator/menu/quit.png'))
        self.file.AppendItem(self.quit)

        ###  Settings for Tools Menu
        self.tools=wx.Menu()

        self.list=wx.Menu()

        self.list.Append(601,"Classes","List Classes in the Module",\
            kind=wx.ITEM_CHECK)
        self.list.Append(602,"Methods","List the Modules in the Module",\
            kind=wx.ITEM_CHECK)
        self.list.Append(603,"Function","List the Functions in the Module",\
            kind=wx.ITEM_CHECK)

        self.action=wx.Menu()

        self.acgen = wx.MenuItem\
            (self.file, 620,"&Generate","Generate Test Routine")
        self.acgen.SetBitmap(wx.Bitmap\
            ('/usr/share/icons/pytestsgenerator/menu/generate.png'))
        self.action.AppendItem(self.acgen)

        self.acust = wx.MenuItem(self.file, 621,\
            "&Customize","Customizable Parameter Settings")
        self.acust.SetBitmap(wx.Bitmap\
            ('/usr/share/icons/pytestsgenerator/menu/customize.png'))
        self.action.AppendItem(self.acust)

        self.acrun = wx.MenuItem(self.file, 622,"&Run",\
            "Run Generated Test Cases")
        self.acrun.SetBitmap(wx.Bitmap\
            ('/usr/share/icons/pytestsgenerator/menu/run.png'))
        self.action.AppendItem(self.acrun)

        self.utility=wx.Menu()

        self.utilbrowse = wx.MenuItem(self.file, 630,\
            "Bro&wse","Browse to select Module")
        self.utilbrowse.SetBitmap(wx.Bitmap\
            ('/usr/share/icons/pytestsgenerator/menu/browse.png'))
        self.utility.AppendItem(self.utilbrowse)

        self.utilprop = wx.MenuItem(self.file, \
            631,"Propert&y","property of the selected window")
        self.utilprop.SetBitmap(wx.Bitmap\
            ('/usr/share/icons/pytestsgenerator/menu/property.png'))
        self.utility.AppendItem(self.utilprop)

        self.utildocs = wx.MenuItem(self.file, 632,"&Docs",\
            "Developers documentation")
        self.utildocs.SetBitmap(wx.Bitmap\
            ('/usr/share/icons/pytestsgenerator/menu/docs.png'))
        self.utility.AppendItem(self.utildocs)

        self.tools.AppendMenu(60,"&List",self.list,\
            "Select the constraints to be displayed")
        self.tools.AppendMenu(62,"&Actions",self.action,\
            "List of action available")
        self.tools.AppendMenu(63,"&Utilities",self.utility,"Utilities")


        ### Setting for Help Menu
        self.help=wx.Menu()

        self.features = wx.MenuItem\
            (self.file,70,"Fea&tures","Help on the PyTestGenerator Features")
        self.features.SetBitmap(wx.Bitmap\
            ('/usr/share/icons/pytestsgenerator/menu/promotion.png'))
        self.help.AppendItem(self.features)

        self.product = wx.MenuItem(self.file,71,"&Product",\
            "Product Documentation")
        self.product.SetBitmap(wx.Bitmap\
            ('/usr/share/icons/pytestsgenerator/menu/product.png'))
        self.help.AppendItem(self.product)

        self.about = wx.MenuItem(self.file,72,"A&bout","About the Application")
        self.about.SetBitmap(wx.Bitmap\
            ('/usr/share/icons/pytestsgenerator/menu/users.png'))
        self.help.AppendItem(self.about)

        self.usage = wx.MenuItem(self.file,73, "Usa&ge","Product Usage")
        self.usage.SetBitmap(wx.Bitmap\
            ('/usr/share/icons/pytestsgenerator/menu/comment.png'))
        self.help.AppendItem(self.usage)

        ###MenuBar Settings
        self.menubar = wx.MenuBar(wx.MB_DOCKABLE)
        self.menubar.Append(self.file, "&File")
        self.menubar.Append(self.tools,"&Tools")
        self.menubar.Append(self.help,"&Help")
        self.SetMenuBar(self.menubar)

        ###Tool Bar Setting

        self.toolbar = self.CreateToolBar()

        self.toolbar.AddLabelTool(1, 'Generate', \
            wx.Bitmap('/usr/share/icons/pytestsgenerator/Generate.png'),\
            shortHelp="Generate",longHelp="Generate Test Cases")
        self.toolbar.AddLabelTool(2, 'CustDef', \
            wx.Bitmap('/usr/share/icons/pytestsgenerator/Customize.png'),\
            shortHelp="Customize",longHelp="Customize the Test Generation Nature")
        self.toolbar.AddLabelTool(3, 'Run', \
            wx.Bitmap('/usr/share/icons/pytestsgenerator/Run.png'),\
            shortHelp="Dry Run",longHelp="Run the last Generated TestCases")
        self.toolbar.Realize()

        ###Display settings

        self.splitter = wx.SplitterWindow(self, 10, style=wx.SP_BORDER)
        self.splitter.SetMinimumPaneSize(50)

        self.avail = wx.ListCtrl(self.splitter, 20,\
            style=wx.LC_REPORT|wx.LC_SORT_ASCENDING)
        self.avail.InsertColumn(0,'ID')
        self.avail.InsertColumn(1,'Entity')
        self.avail.InsertColumn(2,'Sub-Entity')
        self.avail.InsertColumn(3,'Type')
        self.avail.SetColumnWidth(0,80)
        self.avail.SetColumnWidth(1,225)
        self.avail.SetColumnWidth(2,225)
        self.avail.SetColumnWidth(3,200)

        self.avail.SetMinSize((650,300))

        self.selc = wx.ListCtrl(self.splitter, 30,style=wx.LC_REPORT)
        self.selc.InsertColumn(0,'ID')
        self.selc.InsertColumn(1,'Entity')
        self.selc.SetColumnWidth(0,80)
        self.selc.SetColumnWidth(1,350)

        self.splitter.SplitVertically(self.avail, self.selc)
        idle = wx.StaticText(self,60)

        ###Transfer Settings
        self.transizer = wx.BoxSizer(wx.HORIZONTAL)
        self.prop=wx.Button(self, 201, "Properties")
        self.prop.SetToolTip(wx.ToolTip("Identity of the selected Entities"))
        self.ftrans=wx.Button(self, 202, ">>")
        self.ftrans.SetToolTip(wx.ToolTip\
            ("Transfer the Selected Entities for Test Case Generation"))
        self.revtrans=wx.Button(self, 203, "<<")
        self.revtrans.SetToolTip(wx.ToolTip\
            ("Delete the Entity selected for TestCase Generation"))
        self.revtrans.Disable()
        self.docs=wx.Button(self, 204, "Docs")
        self.docs.SetToolTip(wx.ToolTip("Help on the selected module"))
        self.bgen=wx.Button(self, 205, "Generate")
        self.bgen.SetToolTip(wx.ToolTip\
            ("Cases will not be Generated for variables,builtins and modules"))
        self.brbutton = wx.Button(self, 206, "Browse")
        self.brbutton.SetToolTip(wx.ToolTip\
            ("Click to select a module for Test Case Generation"))

        self.transizer.Add(idle,1)
        self.transizer.Add(self.brbutton, 8)
        self.transizer.Add(idle,1)
        self.transizer.Add(self.bgen,8)
        self.transizer.Add(idle,1)
        self.transizer.Add(self.prop,8)
        self.transizer.Add(idle,1)
        self.transizer.Add(self.docs,8)
        self.transizer.Add(idle,1)
        self.transizer.Add(self.ftrans,8)
        self.transizer.Add(idle,4)
        self.transizer.Add(self.revtrans,8)
        self.transizer.Add(idle,4)

        ###Control Settings
        gentext = wx.StaticText(self,301,\
            "Enter Module for TestCases Generation")
        self.genbutton = wx.Button(self, 401, "List")

        self.modname=wx.TextCtrl(self, 50)
        self.modname.SetToolTip(wx.ToolTip("Enter Module Name"))
        self.modname.SetFocus()

        self.contentsizer = wx.BoxSizer(wx.HORIZONTAL)
        self.contentsizer.Add(gentext, 2, wx.EXPAND)
        self.contentsizer.Add(self.modname, 4, wx.EXPAND)
        self.contentsizer.Add(self.genbutton, 1)
        self.contentsizer.Add(idle, 3, wx.EXPAND)

        self.sizer = wx.BoxSizer(wx.VERTICAL)
        self.sizer.Add(self.splitter,3,wx.EXPAND|wx.CENTER)
        self.sizer.Add(self.transizer,0,wx.EXPAND)
        self.sizer.Add(self.contentsizer,0,wx.EXPAND)
        self.SetSizer(self.sizer)

        ###Status Bar Setting
        self.statusbar = self.CreateStatusBar()
        self.SetStatusText("Automated TestCase Generator")
        self.Centre()
        self.Show(True)

        ###Event Initialization

        helper=help.ModuleHelp(self)
        selector=moduledefinitions.Selectmodule(self)
        modhelper=moduledefinitions.Modhelp(self)
        custevent=customize.CustDefinitions(self)
        custview=viewdefinitions.Viewproperty(self)
        genact=genericdefinitions.GenericEvents(self)
        transfer=transferdefinitions.TransferEvents(self)
        generate=generatedefinitions.GenerateEvents(self)
        display=displaydefinitions.Displayselected(self)

        ###Transfer Events

        self.Bind(wx.EVT_BUTTON,transfer.ftrans,id=202)
        self.Bind(wx.EVT_BUTTON,transfer.revtrans,id=203)

        #Genarate Events
        self.Bind(wx.EVT_TOOL,generate.generatecase,id=1)
        self.Bind(wx.EVT_BUTTON,generate.generatecase,id=205)
        self.Bind(wx.EVT_MENU,generate.generatecase,id=620)

        #Customization
        self.Bind(wx.EVT_TOOL,custevent.gatherInfo,id=2)
        self.Bind(wx.EVT_MENU,custevent.gatherInfo,id=621)

        #Run Generated Cases
        self.Bind(wx.EVT_TOOL,activitydefinitions.ActivityEvents(self).run,\
            id=3)
        self.Bind(wx.EVT_MENU,activitydefinitions.ActivityEvents(self).run,\
            id=622)

        #View Events
        self.Bind(wx.EVT_MENU,custview.viewgenerated,id=501)
        self.Bind(wx.EVT_MENU,custview.viewruntest,id=502)

        #Generic Events
        self.Bind(wx.EVT_BUTTON,listingdefinitions.ListEvents(self).listitem,\
            id=401)
        self.Bind(wx.EVT_MENU,genact.onexit,id=52)
        self.Bind(wx.EVT_MENU,genact.toggletoolbar,id=504)
        self.Bind(wx.EVT_MENU,genact.togglestatusbar,id=505)

        #Browse for Module
        self.Bind(wx.EVT_MENU,selector.openmod,id=630)
        self.Bind(wx.EVT_BUTTON,selector.openmod,id=206)

        #Display the properties for selected entities
        self.Bind(wx.EVT_BUTTON,display.gatherinfo,id=201)
        self.Bind(wx.EVT_MENU,display.gatherinfo,id=631)
        self.Bind(wx.EVT_BUTTON,modhelper.gatherinfo,id=204)
        self.Bind(wx.EVT_MENU,modhelper.gatherinfo,id=632)

        #Help Menu
        self.Bind(wx.EVT_MENU,helper.feature,id=70)
        self.Bind(wx.EVT_MENU,helper.product,id=71)
        self.Bind(wx.EVT_MENU,helper.usage,id=73)
        self.Bind(wx.EVT_MENU,genact.about,id=72)
